package itsm.isperp.job;

import itsm.isperp.module.service.slm.SlmServiceAgreementService;

import java.util.Date;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * SLM服务计算作业,通过指定的时间更新间隔更新服务，以及产生相关的告警建议。运行间隔设置为30-60秒
 * 
 * @author lizx
 * @date 2013-7-31
 * 
 */
@Service
public class SlmServiceElapsedJob implements Job {

	public static final Logger logger = LoggerFactory
			.getLogger(SlmServiceElapsedJob.class);

	@Autowired
	protected SlmServiceAgreementService slmServiceAgreementService;

	@Override
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		logger.info("elapseing Worktime.");
		Date date = context.getPreviousFireTime();
		if (date == null)
			return;
		//
		long interval = (new Date().getTime() - date.getTime()) / (1000);
		slmServiceAgreementService.elapsedWorktime(interval);
	}
}
